package com.pig4cloud.pig.common.mybatis.config;

import com.alibaba.druid.pool.DruidDataSource;
//import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
//import io.seata.rm.datasource.DataSourceProxy;
import javax.sql.DataSource;

//用于Seata的数据源配置(暂时无用)
//@Configuration
public class DataSourceConfig {


	/**
	 * 从配置文件获取属性构造datasource，注意前缀，这里用的是druid，根据自己情况配置,
	 * 原生datasource前缀取"spring.datasource"
	 *
	 * @return
	 */
	@ConfigurationProperties(prefix = "spring.datasource")
	@Bean
	public DruidDataSource druidDataSource(){
		return new DruidDataSource();
	}
	/**
	 * 构造datasource代理对象，替换原来的datasource
	 *
	 * @param druidDataSource
	 * @return
	 */
	@Primary
	@Bean("dataSource")
	public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) {
		return new DataSourceProxy(druidDataSource);
	}

	/*@Primary
	@Bean("dataSource")
	public DataSourceProxy dataSourceProxy(DataSource druidDataSource) {

		return new DataSourceProxy(druidDataSource);
	}*/
}